package com.sgb.kjwl.view.ui.activity.material.hall;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.ScrollBoundaryDecider;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.UrlConfig;
import com.sgb.kjwl.databinding.FragmentNewPickHallBinding;
import com.sgb.kjwl.di.home.DaggerHomeFragComponent;
import com.sgb.kjwl.di.home.HomeFragModule;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.kjwl.model.entity.pick.PreNoticeItemEntity;
import com.sgb.kjwl.model.entity.pick.TenderAllListNewEntity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.pick.PickNoticeDetailActivity;
import com.sgb.kjwl.view.ui.activity.pick.TenderDetailsActivity3;
import com.sgb.kjwl.view.ui.adapter.pick.PickHallAllNewAdapter;
import com.sgb.kjwl.view.ui.adapter.pick.PickNoticeListAdapter;
import com.sgb.kjwl.view.ui.fragment.MainRecruitmentFragment;
import com.sgb.kjwl.view.widget.PickHallBidingPopWindow;
import com.sgb.kjwl.view.widget.pick.PickPopWindowView;
import com.sgb.kjwl.viewmodel.home.NewPickHallFragModel;
import com.sgb.zhaocai.entity.DemandForecastListBean;
import com.sgb.zhaocai.entity.DemandForecastListEntity;
import com.sgb.zhaocai.view.demand.adapter.DemandListAdapter;
import com.sgb.zhaocai.widget.threefliter.ZCThreeLevelFilterWindow;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.refresh.SuperSwipeRefreshLayout;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.areapopup.GoodsSourceLocationEntity;
import com.swgk.core.view.areapopup.ThreeLevelAreaWindow;
import com.swgk.core.view.selection.CommonPopEntity;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 首页招标大厅，招标公告
 */
public class NewPickHallFragment extends AppLazyFragment {

    @Inject
    NewPickHallFragModel viewModel;
    FragmentNewPickHallBinding binding;

    //0首页-招标大厅  1首页-招标公告
    public static final String FROM_WHERE = "FROM_WHERE";

    private PickHallBidingPopWindow pickAllPopWindow;
    private PickHallBidingPopWindow pickGoodsTypePopWindow;
    private PickHallBidingPopWindow pickStatusPopWindow;
    private PickHallBidingPopWindow pickApplyTimePopWindow;
    private PickHallBidingPopWindow pickEndTimePopWindow;
    private PickHallBidingPopWindow pickMoneyPopWindow;
    private PickHallBidingPopWindow pickTenderTypePopWindow;
    private PickHallBidingPopWindow demandTypePopWindow;
    private PickHallBidingPopWindow projectTypePopWindow;
    private PickHallBidingPopWindow releaseTimePopWindow;
    private ThreeLevelAreaWindow mAddressPop;

    private List<PickSelectEntity> startTimeData = new ArrayList<>();
    private List<PickSelectEntity> allHallData = new ArrayList<>();
    private List<PickSelectEntity> goodsTypeData = new ArrayList<>();
    private List<PickSelectEntity> statusDate = new ArrayList<>();
    private List<PickSelectEntity> endTimeDate = new ArrayList<>();
    private List<PickSelectEntity> moneyData = new ArrayList<>();
    private List<PickSelectEntity> tenderTypeDate = new ArrayList<>();
    private List<PickSelectEntity> projectTypeDate = new ArrayList<>();
    private List<PickSelectEntity> releaseTimeDate = new ArrayList<>();
    private List<PickSelectEntity> demandTypeDate = new ArrayList<>();
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> scrData;
    //需求预告请求类
    private DemandForecastListBean requestBean = new DemandForecastListBean();
    //全部
    private String allNo = "0";
    private String allName;
    //类型
    private String goodsType;
    private String goodsTypeName;
    //招标状态
    private String statusNo;
    private String statusName;
    //开始时间
    private String applyTimeNo;
    private String applyTimeName;
    //结束时间
    private String endTimeNo;
    private String endTimeName;
    //预算金额
    private String money;
    private String moneyName;
    //资格审查方式
    private String tenderTypeNo;
    private String tenderTypeName;
    //省
    private String areaCode;
    private String areaName;
    private String cityNo;
    //需求类型
    private String demandTypeNo = "0";
    private String demandTypeName = "";
    //工程类型
    private String projectTypeName = "";
    //发布时间
    private String releaseTimeNo = "";
    private String releaseTimeName = "";

    private int page = 1;
    private boolean isLoadMore = false;
    private SuperSwipeRefreshLayout swipeRefreshMainRecruitmentFragment;

    private PickHallAllNewAdapter pickBidingAdapter;
    private PickNoticeListAdapter pickNoticeListAdapter;
    private PickHallAllNewAdapter pickHallAllNewAdapter;
    private PickHallAllNewAdapter pickingAdapter;
    private DemandListAdapter demandlistadapter;

    private String fromWhere;
    //经纬度
    private String longitude = "";
    private String latitude = "";
    private List<CommonPopEntity> commonlist;
    private ZCThreeLevelFilterWindow popCategory;
    private String typeName1 = "";
    private String mNo1 = "";
    private String mNo2 = "";
    private String mNo3 = "";
    private boolean isEnableLoadMore = false; //是否可以上拉加载


    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerHomeFragComponent
                .builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    public static NewPickHallFragment newInstance(String fromWhere) {
        NewPickHallFragment fragment = new NewPickHallFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FROM_WHERE, fromWhere);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_new_pick_hall, container, false);
        fromWhere = getArguments().getString(FROM_WHERE);
        return binding.getRoot();
    }

    @Override
    protected void onLazyLoad() {
        initData();
        initAdapter();
    }

    @Override
    protected void initView() {
        super.initView();
        initPopWindow();
        init();
    }

    private void init() {
        longitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        latitude = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
        if (TextUtils.isEmpty(longitude)) {
            longitude = "0";
        }
        if (TextUtils.isEmpty(latitude)) {
            longitude = "0";
        }
        requestBean.setLocalLat(latitude);
        requestBean.setLocalLng(longitude);
        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shape_list_divide2));
        binding.recyclerView.addItemDecoration(divider);

        binding.swipeRefresh.setEnableRefresh(false);
        binding.swipeRefresh.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                isLoadMore = true;
                requestBean.page = page;
                if ("0".equals(allNo)) {  //全部---类型 地区
                    if ("0".equals(fromWhere)) {
                        viewModel.findTenderingHomeEsPage(page, goodsType, areaCode, cityNo);
                    } else if ("1".equals(fromWhere)) {
                        viewModel.findNoticeHomeEsPage(page, goodsType, areaCode, cityNo);
                    }
                } else if ("1".equals(allNo)) {   //0招标大厅 招标公告---类型 招标状态 预算金额  资格审查方式  地区      1招标公告 招标报名---类型 报名结束时间 预算金额 资格审查方式 地区
                    if ("0".equals(fromWhere)) {
                        viewModel.tenderBidderList(page, goodsType, areaCode, cityNo, money, statusNo, tenderTypeNo);
                    } else if ("1".equals(fromWhere)) {
                        viewModel.getFindPreBiddingList(page, goodsType, areaCode, cityNo, money, endTimeNo, tenderTypeNo);
                    }
                } else if ("2".equals(allNo)) {   //直接竞价---类型 预算金额 地区
                    viewModel.getBiddingList(page, goodsType, areaCode, cityNo, money,fromWhere);
                } else if ("3".equals(allNo)) {   //招标预告---类型 报名开始时间 预算金额 资格审查方式 地区
                    viewModel.tenderNoticeList(page, goodsType, areaCode, cityNo, money, applyTimeNo, tenderTypeNo);
                } else if ("4".equals(allNo)) {
                    viewModel.getMaterialHomeList(demandTypeNo, requestBean);
                }
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                initFilterData();
                binding.swipeRefresh.finishRefresh(300);
            }
        });
        //解决 在实现 上拉加载更多 和 下拉刷新 时  遇到item不在顶端就执行了刷新的方法和数据item没有填满屏幕也执行了加载更多
        binding.swipeRefresh.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
            @Override
            public boolean canRefresh(View content) {
                if (binding.scrollview == null) return false;
                if (binding.scrollview.computeVerticalScrollOffset() == 0)
                    return true;
                return false;
            }

            @Override
            public boolean canLoadMore(View content) {
                if (binding.scrollview == null) return false;
                //获取recyclerView的高度
                binding.scrollview.getHeight();
                //整个View控件的高度
                int scrollRange = binding.scrollview.computeVerticalScrollRange();
                //当前屏幕之前滑过的距离
                int scrollOffset = binding.scrollview.computeVerticalScrollOffset();
                //当前屏幕显示的区域高度
                int scrollExtent = binding.scrollview.computeVerticalScrollExtent();
                int height = binding.scrollview.getHeight();
                if (height > scrollRange) {
                    return false;
                }
                if (isEnableLoadMore && scrollRange <= scrollOffset + scrollExtent) {
                    return true;
                }
                return false;
            }
        });

    }

    /**
     * 下拉刷新界面
     *
     * @param swipeRefreshMainRecruitmentFragment
     */
    public void onPullRefresh(SuperSwipeRefreshLayout swipeRefreshMainRecruitmentFragment) {
        this.swipeRefreshMainRecruitmentFragment = swipeRefreshMainRecruitmentFragment;
        swipeRefreshMainRecruitmentFragment.setLoadMore(false);
        initFilterData();
    }

    private void initPopWindow() {
        //全部
        pickAllPopWindow = new PickHallBidingPopWindow(getActivity());
        pickAllPopWindow.setBgView(binding.grayLayout);
        pickAllPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                allNo = ((PickSelectEntity) key1).getNo();
                allName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(allName)) {
                    updateChooseTextStatus1(binding.tvAll, 1, allName);
                } else {
                    allName = "全部";
                    updateChooseTextStatus1(binding.tvAll, 0, allName);
                }
                clearPopWindowData();
                initAdapter();
                updateViewShow();
            }
        });
        pickAllPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("全部".equals(allName)) {
                    updateChooseTextStatus1(binding.tvAll, 0, allName);
                } else {
                    updateChooseTextStatus1(binding.tvAll, 1, allName);
                }
            }
        });
        //类型
        pickGoodsTypePopWindow = new PickHallBidingPopWindow(getActivity());
        pickGoodsTypePopWindow.setBgView(binding.grayLayout);
        pickGoodsTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                goodsType = ((PickSelectEntity) key1).getNo();
                goodsTypeName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(goodsTypeName)) {
                    updateChooseTextStatus(binding.tvCategory, 1, goodsTypeName);
                } else {
                    goodsTypeName = "类型";
                    updateChooseTextStatus(binding.tvCategory, 0, goodsTypeName);
                }
                initFilterData();
            }
        });
        pickGoodsTypePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("类型".equals(goodsTypeName)) {
                    updateChooseTextStatus(binding.tvCategory, 0, goodsTypeName);
                } else {
                    updateChooseTextStatus(binding.tvCategory, 1, goodsTypeName);
                }
            }
        });
        //招标状态
        pickStatusPopWindow = new PickHallBidingPopWindow(getActivity());
        pickStatusPopWindow.setBgView(binding.grayLayout);
        pickStatusPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                statusNo = ((PickSelectEntity) key1).getNo();
                statusName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(statusName)) {
                    updateChooseTextStatus(binding.tvStatus, 1, statusName);
                } else {
                    statusName = "招标状态";
                    updateChooseTextStatus(binding.tvStatus, 0, statusName);
                }
                initFilterData();
            }
        });
        pickStatusPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("招标状态".equals(statusName)) {
                    updateChooseTextStatus(binding.tvStatus, 0, statusName);
                } else {
                    updateChooseTextStatus(binding.tvStatus, 1, statusName);
                }
            }
        });
        // 报名开始时间
        pickApplyTimePopWindow = new PickHallBidingPopWindow(getActivity());
        pickApplyTimePopWindow.setBgView(binding.grayLayout);
        pickApplyTimePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                applyTimeNo = ((PickSelectEntity) key1).getNo();
                applyTimeName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(applyTimeName)) {
                    updateChooseTextStatus(binding.tvApplyTime, 1, applyTimeName);
                } else {
                    applyTimeName = "报名开始时间";
                    updateChooseTextStatus(binding.tvApplyTime, 0, applyTimeName);
                }
                initFilterData();
            }
        });
        pickApplyTimePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("报名开始时间".equals(applyTimeName)) {
                    updateChooseTextStatus(binding.tvApplyTime, 0, applyTimeName);
                } else {
                    updateChooseTextStatus(binding.tvApplyTime, 1, applyTimeName);
                }
            }
        });
        //报名结束时间
        pickEndTimePopWindow = new PickHallBidingPopWindow(getActivity());
        pickEndTimePopWindow.setBgView(binding.grayLayout);
        pickEndTimePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                endTimeNo = ((PickSelectEntity) key1).getNo();
                endTimeName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(endTimeName)) {
                    updateChooseTextStatus(binding.tvEndTime, 1, endTimeName);
                } else {
                    endTimeName = "报名结束时间";
                    updateChooseTextStatus(binding.tvEndTime, 0, endTimeName);
                }
                initFilterData();
            }
        });
        pickEndTimePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("报名结束时间".equals(endTimeName)) {
                    updateChooseTextStatus(binding.tvEndTime, 0, endTimeName);
                } else {
                    updateChooseTextStatus(binding.tvEndTime, 1, endTimeName);
                }
            }
        });
        //预算金额
        pickMoneyPopWindow = new PickHallBidingPopWindow(getActivity());
        pickMoneyPopWindow.setBgView(binding.grayLayout);
        pickMoneyPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                money = ((PickSelectEntity) key1).getNo();
                moneyName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(moneyName)) {
                    updateChooseTextStatus(binding.tvMoney, 1, moneyName);
                } else {
                    moneyName = "预算金额";
                    updateChooseTextStatus(binding.tvMoney, 0, moneyName);
                }
                initFilterData();
            }
        });
        pickMoneyPopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("预算金额".equals(moneyName)) {
                    updateChooseTextStatus(binding.tvMoney, 0, moneyName);
                } else {
                    updateChooseTextStatus(binding.tvMoney, 1, moneyName);
                }
            }
        });
        //资格审查方式
        pickTenderTypePopWindow = new PickHallBidingPopWindow(getActivity());
        pickTenderTypePopWindow.setBgView(binding.grayLayout);
        pickTenderTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                tenderTypeNo = ((PickSelectEntity) key1).getNo();
                tenderTypeName = ((PickSelectEntity) key1).getProjectscale();
                if (!"全部".equals(tenderTypeName)) {
                    updateChooseTextStatus(binding.tvTenderType, 1, tenderTypeName);
                } else {
                    tenderTypeName = "资格审查方式";
                    updateChooseTextStatus(binding.tvTenderType, 0, tenderTypeName);
                }
                initFilterData();
            }
        });
        pickTenderTypePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("资格审查方式".equals(tenderTypeName)) {
                    updateChooseTextStatus(binding.tvTenderType, 0, tenderTypeName);
                } else {
                    updateChooseTextStatus(binding.tvTenderType, 1, tenderTypeName);
                }
            }
        });

        //需求类型
        demandTypePopWindow = new PickHallBidingPopWindow(getActivity());
        demandTypePopWindow.setBgView(binding.grayLayout);
        demandTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                demandTypeNo = ((PickSelectEntity) key1).getNo();
                demandTypeName = ((PickSelectEntity) key1).getProjectscale();
                if (TextUtils.equals(demandTypeName, "劳务用工") || TextUtils.equals(demandTypeName, "分包计划")) {
                    binding.tvProjectType.setVisibility(View.VISIBLE);
                } else {
                    binding.tvProjectType.setVisibility(View.GONE);
                }
                if (TextUtils.equals(demandTypeName, "材料采购") || TextUtils.equals(demandTypeName, "机械租赁") || TextUtils.equals(demandTypeName, "设备租赁")) {
                    binding.type.setVisibility(View.VISIBLE);
                } else {
                    binding.type.setVisibility(View.GONE);
                }
                mNo1 = "";
                mNo2 = "";
                mNo3 = "";
                typeName1 = "";
                requestBean.setCategoryId("");
                switch (demandTypeNo) {
                    case "0"://获取材料类型
                        viewModel.getMaterialType();
                        break;
                    case "1"://获取机械类型
                        viewModel.getMechanicalType();
                        break;
                    case "2"://获取设备类型
                        viewModel.getEquipmentType();
                        break;
                }
                updateChooseTextStatus(binding.tvDemandType, 1, demandTypeName);
                initFilterData();
            }
        });
        demandTypePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                updateChooseTextStatus(binding.tvDemandType, 1, demandTypeName);
            }
        });

        //需求类型
        projectTypePopWindow = new PickHallBidingPopWindow(getActivity());
        projectTypePopWindow.setBgView(binding.grayLayout);
        projectTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                projectTypeName = ((PickSelectEntity) key1).getProjectscale();
                if (!"不限".equals(projectTypeName)) {
                    requestBean.setEngineeringType(projectTypeName);
                    updateChooseTextStatus(binding.tvProjectType, 1, projectTypeName);
                } else {
                    projectTypeName = "工程类型";
                    requestBean.setEngineeringType("");
                    updateChooseTextStatus(binding.tvProjectType, 0, projectTypeName);
                }
                initFilterData();
            }
        });
        projectTypePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("工程类型".equals(projectTypeName)) {
                    updateChooseTextStatus(binding.tvProjectType, 0, projectTypeName);
                } else {
                    updateChooseTextStatus(binding.tvProjectType, 1, projectTypeName);
                }
            }
        });

        //发布时间
        releaseTimePopWindow = new PickHallBidingPopWindow(getActivity());
        releaseTimePopWindow.setBgView(binding.grayLayout);
        releaseTimePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                releaseTimeNo = ((PickSelectEntity) key1).getNo();
                releaseTimeName = ((PickSelectEntity) key1).getProjectscale();
                requestBean.setPlanUseTime(releaseTimeNo);
                if (!"不限".equals(releaseTimeName)) {
                    updateChooseTextStatus(binding.tvReleaseTime, 1, releaseTimeName);
                } else {
                    releaseTimeName = "发布时间";
                    updateChooseTextStatus(binding.tvReleaseTime, 0, releaseTimeName);
                }
                initFilterData();
            }
        });
        releaseTimePopWindow.setOnDisMissClick(new BasePopWindow.OnDisMiss() {
            @Override
            public void disMiss() {
                if ("发布时间".equals(releaseTimeName)) {
                    updateChooseTextStatus(binding.tvReleaseTime, 0, releaseTimeName);
                } else {
                    updateChooseTextStatus(binding.tvReleaseTime, 1, releaseTimeName);
                }
            }
        });
        initAddressPopup();
        //类型处理
        initCateGoryPopup();
        binding.tvAll.setOnClickListener(this);
        binding.tvCategory.setOnClickListener(this);
        binding.tvTenderType.setOnClickListener(this);
        binding.tvMoney.setOnClickListener(this);
        binding.tvEndTime.setOnClickListener(this);
        binding.tvStatus.setOnClickListener(this);
        binding.tvApplyTime.setOnClickListener(this);
        binding.tvAddress.setOnClickListener(this);
        binding.tvDemandType.setOnClickListener(this);
        binding.tvProjectType.setOnClickListener(this);
        binding.tvReleaseTime.setOnClickListener(this);
        binding.type.setOnClickListener(this);
    }

    private void initCateGoryPopup() {
        popCategory = new ZCThreeLevelFilterWindow(getContext());
        popCategory.setBgView(binding.grayLayout);
        popCategory.setOnResultClick(new ZCThreeLevelFilterWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                CommonPopEntity pickResultProject1 = (CommonPopEntity) key1;
                CommonPopEntity pickResultProject2 = (CommonPopEntity) key2;
                CommonPopEntity pickResultProject3 = (CommonPopEntity) key3;
                switch (demandTypeNo) {
                    case "0"://材料
                        if (pickResultProject1 != null && !TextUtils.isEmpty(pickResultProject1.getTypeName())) {
                            if (!"全部".equals(pickResultProject1.getTypeName())) {
                                typeName1 = pickResultProject1.getTypeName();
                                mNo1 = pickResultProject1.getId();
                                requestBean.setCategoryId(mNo1);
                            }else {
                                typeName1 = "";
                                mNo1 = "";
                                mNo2 = "";
                                mNo3 = "";
                                requestBean.setCategoryId("");
                                popCategory.setData(commonlist, 0);
                            }
                        }
                        if (pickResultProject2 != null && !TextUtils.isEmpty(pickResultProject2.getTypeName())) {
                            if (!"全部".equals(pickResultProject2.getTypeName())) {
                                typeName1 = pickResultProject2.getTypeName();
                                mNo2 = pickResultProject2.getId();
                                requestBean.setCategoryId(mNo2);
                            }
                        }
                        if (pickResultProject3 != null && !TextUtils.isEmpty(pickResultProject3.getTypeName())) {
                            if (!"全部".equals(pickResultProject3.getTypeName())) {
                                typeName1 = pickResultProject3.getTypeName();
                                mNo3 = pickResultProject3.getId();
                                requestBean.setCategoryId(mNo3);
                            }
                        }
                        binding.type.updateChooseTextStatus(1, TextUtils.isEmpty(typeName1)? binding.type.getKeyName():typeName1);
                        break;
                    case "1"://机械
                    case "2"://设备
                        if (pickResultProject1 != null && !TextUtils.isEmpty(pickResultProject1.getTypeName())) {
                            if (!"全部".equals(pickResultProject1.getTypeName())) {
                                typeName1 = pickResultProject1.getTypeName();
                                mNo1 = pickResultProject1.getNo();
                                requestBean.setCategoryId(mNo1);
                            }else {
                                typeName1 = "";
                                mNo1 = "";
                                mNo2 = "";
                                mNo3 = "";
                                requestBean.setCategoryId("");
                                popCategory.setData(commonlist, 0);
                            }
                        }
                        if (pickResultProject2 != null && !TextUtils.isEmpty(pickResultProject2.getTypeName())) {
                            if (!"全部".equals(pickResultProject2.getTypeName())) {
                                typeName1 = pickResultProject2.getTypeName();
                                mNo2 = pickResultProject2.getNo();
                                requestBean.setCategoryId(mNo2);
                            }
                        }
                        binding.type.updateChooseTextStatus(1, TextUtils.isEmpty(typeName1)? binding.type.getKeyName():typeName1);
                        break;
                }
                //刷新数据
                initFilterData();
            }

            @Override
            public void reset() {
                mNo1 = "";
                mNo2 = "";
                mNo3 = "";
                requestBean.setCategoryId("");
                popCategory.setData(commonlist, 0);
                binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
                //刷新数据
                initFilterData();
            }
        });
        popCategory.setOnDismissListener(() -> {
            if (TextUtils.equals(demandTypeNo, "1")) {
                if (!TextUtils.isEmpty(mNo1) || !TextUtils.isEmpty(mNo2) || !TextUtils.isEmpty(mNo3)) {
                    binding.type.updateChooseTextStatus(1, null);
                } else {
                    binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
                }
            } else {
                if (!TextUtils.isEmpty(mNo1) || !TextUtils.isEmpty(mNo2)) {
                    binding.type.updateChooseTextStatus(1, null);
                } else {
                    binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
                }
            }
        });
    }


    private void initAddressPopup() {
        mAddressPop = new ThreeLevelAreaWindow(getActivity());
        mAddressPop.setMemberHeight();
        mAddressPop.setCitySingle();
        mAddressPop.setProvinceSingle();
        mAddressPop.setShowSimpleName(true);
        mAddressPop.setOnlyShowProAndCity(true);
        mAddressPop.setAllSingleSelect(true);
        mAddressPop.setThreeListIsGone(true);
        mAddressPop.setOnResultClick(new ThreeLevelAreaWindow.OnResultClickProxy() {
            @Override
            protected void result(GoodsSourceLocationEntity entity) {
                areaCode = entity.getProvinceNo();
                if (!TextUtils.isEmpty(entity.getProvinceNo())) {
                    areaName = entity.getProvinceName();
                    areaCode = entity.getProvinceNo();
                    requestBean.setProvince(areaCode);
                    cityNo = "";
                    requestBean.setCity(cityNo);
                    if ("0".equals(areaCode)) {
                        areaName = "地区";
                    }

                    updateChooseTextStatus(binding.tvAddress, 1, areaName);
                    if (!TextUtils.isEmpty(entity.getCityNo())) {
                        cityNo = entity.getCityNo();
                        areaName = entity.getCityName();
                        mAddressPop.setData(scrData, true);
                        requestBean.setCity(cityNo);
                        updateChooseTextStatus(binding.tvAddress, 1, areaName);
                    }
                } else {
                    areaName = "地区";
                    areaCode = "";
                    cityNo = "";
                    requestBean.setProvince(areaCode);
                    requestBean.setCity(cityNo);
                    updateChooseTextStatus(binding.tvAddress, 0, areaName);
                }
                initFilterData();
            }
        });
        mAddressPop.setOnDismissListener(() -> {
            updateChooseTextStatus(binding.tvAddress, "地区".equals(areaName) ? 0 : 1, areaName);
        });
    }

    private void clearPopWindowData() {
        if (!"全部".equals(goodsTypeName)) {
            goodsType = "";
            goodsTypeName = "";
            updateChooseTextStatus(binding.tvCategory, 0, goodsTypeName);
        }
        if (!"全部".equals(statusName)) {
            statusNo = "";
            statusName = "";
            updateChooseTextStatus(binding.tvStatus, 0, statusName);
        }
        if (!"全部".equals(applyTimeName)) {
            applyTimeNo = "";
            applyTimeName = "";
            updateChooseTextStatus(binding.tvApplyTime, 0, applyTimeName);
        }
        if (!"全部".equals(endTimeName)) {
            endTimeNo = "";
            endTimeName = "";
            updateChooseTextStatus(binding.tvEndTime, 0, endTimeName);
        }
        if (!"全部".equals(moneyName)) {
            money = "";
            moneyName = "";
            updateChooseTextStatus(binding.tvMoney, 0, moneyName);
        }
        if (!"全部".equals(tenderTypeName)) {
            tenderTypeNo = "";
            tenderTypeName = "";
            updateChooseTextStatus(binding.tvTenderType, 0, tenderTypeName);
        }
        areaCode = "";
        areaName = "";
        cityNo = "";
        updateChooseTextStatus(binding.tvAddress, 0, areaName);
        mAddressPop.setDefPosition(0, 0);
        // binding.imgBackTop.setVisibility(View.GONE);
    }

    private void initData() {
        //全部
        if ("0".equals(fromWhere)) {
            String[] stringHall = new String[]{"全部&0", "招标公告&1", "直接竞价&2", "招标预告&3", "需求预告&4"};
            setAllHallData(stringHall);
        } else if ("1".equals(fromWhere)) {
            String[] stringHall = new String[]{"全部&0", "招标报名&1", "直接竞价&2", "招标预告&3"};
            setAllHallData(stringHall);
        }

        //报名开始时间
        String[] stringTime = new String[]{"全部", "今天&1", "3天内&3", "5天内&5", "10天内&10", "15天内&15", "20天内&20", "30天内&30", "30天以上&31"};
        setStartTimeData(stringTime);

        viewModel.getProvinceData();
        viewModel.getFilterTypeData();
        viewModel.getPriceData();
        viewModel.getPickTimes();
        viewModel.getStatusData();
        viewModel.getTenderNewTypeList();
        viewModel.getDemandTypeList();
        viewModel.getProjectTypeList();
        viewModel.getReleaseTimeList();
    }

    private void initAdapter() {

        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        binding.recyclerView.setLayoutManager(layoutManager);

        if ("0".equals(allNo)) {  //全部

            if (pickHallAllNewAdapter == null) {
                pickHallAllNewAdapter = new PickHallAllNewAdapter(getContext(), null);
            }
            binding.recyclerView.setAdapter(pickHallAllNewAdapter);

            pickHallAllNewAdapter.setOnItemClick(new AdapterOnItemClick<TenderAllListNewEntity>() {
                @Override
                public void onItemClick(TenderAllListNewEntity tenderAllListNewEntity, int position) {
                    if (tenderAllListNewEntity.getDataSources() == 1) { //1.经营帮 2.政府网站
                        if (tenderAllListNewEntity.getBusinessType() == 1) {
                            if (tenderAllListNewEntity.getState() == 8) {
                                PickNoticeDetailActivity.start(getActivity(), tenderAllListNewEntity.getId() + "");
                            } else {
                                TenderDetailsActivity3.start(getContext(), tenderAllListNewEntity.getId() + "", 0);
                            }
                        } else if (tenderAllListNewEntity.getBusinessType() == 2) {
                            viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                        }
                    }  else if (tenderAllListNewEntity.getDataSources() == 2) {
                        viewModel.getUrlSettingSj(tenderAllListNewEntity.getId());
                    }
                }
            });

            pickHallAllNewAdapter.onIChildClick(new PickHallAllNewAdapter.IChildClick() {
                @Override
                public void onClick(TenderAllListNewEntity tenderAllListNewEntity) {
                    if (tenderAllListNewEntity.getDataSources() == 1) { //1.经营帮 2.政府网站
                        if (tenderAllListNewEntity.getBusinessType() == 1) {
                            if (tenderAllListNewEntity.getState() == 8) {
                                PickNoticeDetailActivity.start(getActivity(), tenderAllListNewEntity.getId() + "");
                            } else {
                                TenderDetailsActivity3.start(getContext(), tenderAllListNewEntity.getId() + "", 0);
                            }
                        } else if (tenderAllListNewEntity.getBusinessType() == 2) {
                            viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                        }
                    } else if (tenderAllListNewEntity.getDataSources() == 2) {
                        viewModel.getUrlSettingSj(tenderAllListNewEntity.getId());
                    }
                }
            });

        } else if("1".equals(allNo)){

            if (pickingAdapter == null) {
                pickingAdapter = new PickHallAllNewAdapter(getContext(), null);
            }
            binding.recyclerView.setAdapter(pickingAdapter);

            pickingAdapter.setOnItemClick(new AdapterOnItemClick<TenderAllListNewEntity>() {
                @Override
                public void onItemClick(TenderAllListNewEntity tenderAllListNewEntity, int position) {
                    if (tenderAllListNewEntity.getDataSources() == 1) { //1.经营帮 2.政府网站
                        if (tenderAllListNewEntity.getBusinessType() == 1) {
                            if (tenderAllListNewEntity.getState() == 8) {
                                PickNoticeDetailActivity.start(getActivity(), tenderAllListNewEntity.getId() + "");
                            } else {
                                TenderDetailsActivity3.start(getContext(), tenderAllListNewEntity.getId() + "", 0);
                            }
                        } else if (tenderAllListNewEntity.getBusinessType() == 2) {
                            viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                        }
                    }  else if (tenderAllListNewEntity.getDataSources() == 2) {
                        viewModel.getUrlSettingSj(tenderAllListNewEntity.getId());
                    }
                }
            });

            pickingAdapter.onIChildClick(new PickHallAllNewAdapter.IChildClick() {
                @Override
                public void onClick(TenderAllListNewEntity tenderAllListNewEntity) {
                    if (tenderAllListNewEntity.getDataSources() == 1) { //1.经营帮 2.政府网站
                        if (tenderAllListNewEntity.getBusinessType() == 1) {
                            if (tenderAllListNewEntity.getState() == 8) {
                                PickNoticeDetailActivity.start(getActivity(), tenderAllListNewEntity.getId() + "");
                            } else {
                                TenderDetailsActivity3.start(getContext(), tenderAllListNewEntity.getId() + "", 0);
                            }
                        } else if (tenderAllListNewEntity.getBusinessType() == 2) {
                            viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                        }
                    }  else if (tenderAllListNewEntity.getDataSources() == 2) {
                        viewModel.getUrlSettingSj(tenderAllListNewEntity.getId());
                    }
                }
            });

        }else if ("2".equals(allNo)) {   //直接竞价

            if (pickBidingAdapter == null) {
                pickBidingAdapter = new PickHallAllNewAdapter(getContext(), null);
            }
            binding.recyclerView.setAdapter(pickBidingAdapter);
            pickBidingAdapter.setOnItemClick(new AdapterOnItemClick<TenderAllListNewEntity>() {
                @Override
                public void onItemClick(TenderAllListNewEntity tenderAllListNewEntity, int position) {
                    viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                }
            });
            pickBidingAdapter.onIChildClick(new PickHallAllNewAdapter.IChildClick() {
                @Override
                public void onClick(TenderAllListNewEntity tenderAllListNewEntity) {
                    viewModel.getUrlSetting(tenderAllListNewEntity.getId());
                }
            });

        } else if ("3".equals(allNo)) {   //招标预告

            if (pickNoticeListAdapter == null) {
                pickNoticeListAdapter = new PickNoticeListAdapter(getContext(), null);
            }
            binding.recyclerView.setAdapter(pickNoticeListAdapter);
            pickNoticeListAdapter.onIChildClick(new PickNoticeListAdapter.IChildClick() {
                @Override
                public void onClick(PreNoticeItemEntity preNoticeItemEntity) {
                    if (preNoticeItemEntity.getTenderState() == 8) {
                        PickNoticeDetailActivity.start(getContext(), preNoticeItemEntity.getTenderNo() + "");
                    } else {
                        TenderDetailsActivity3.start(getContext(), preNoticeItemEntity.getId() + "", 0);
                    }
                }
            });
            pickNoticeListAdapter.setOnItemClick(new AdapterOnItemClick<PreNoticeItemEntity>() {
                @Override
                public void onItemClick(PreNoticeItemEntity preNoticeItemEntity, int position) {
                    if (preNoticeItemEntity.getTenderState() == 8) {
                        PickNoticeDetailActivity.start(getContext(), preNoticeItemEntity.getTenderNo() + "");
                    } else {
                        TenderDetailsActivity3.start(getContext(), preNoticeItemEntity.getId() + "", 0);
                    }
                }
            });
        } else if ("4".equals(allNo)) {
            if (demandlistadapter == null) {
                demandlistadapter = new DemandListAdapter(getActivity(), null);
            }
            binding.recyclerView.setHasFixedSize(true);
            //解决数据加载完成后, 没有停留在顶部的问题
            binding.recyclerView.setFocusable(false);
            binding.recyclerView.setAdapter(demandlistadapter);
            demandlistadapter.setOnItemClick(new AdapterOnItemClick<DemandForecastListEntity>() {
                @Override
                public void onItemClick(DemandForecastListEntity demandForecastListEntity, int position) {
                    viewModel.getWebH5(demandForecastListEntity.getId(), demandForecastListEntity.getModuleType());
                }
            });
            demandlistadapter.setOnItemStateOperate(new DemandListAdapter.OnItemStateOperate() {
                @Override
                public void OnItem(DemandForecastListEntity entity) {
                    viewModel.getWebH5(entity.getId(), entity.getModuleType());
                }
            });
        }
        initFilterData();
    }

    private void setAllHallData(String[] strings) {
        for (String s : strings) {
            PickSelectEntity pickSelectEntity = new PickSelectEntity();
            if (s.contains("&")) {
                String[] splitText = s.split("&");
                pickSelectEntity.setNo(splitText[1]);
                pickSelectEntity.setProjectscale(splitText[0]);
            } else {
                pickSelectEntity.setNo("");
                pickSelectEntity.setProjectscale(s);
            }
            allHallData.add(pickSelectEntity);
        }
    }

    /**
     * 类型
     */
    public void setFilterTypeData(List<PickSelectEntity> data) {
        goodsTypeData.clear();
        goodsTypeData.addAll(data);
    }

    /**
     * 预算金额
     */
    public void setPriceData(List<PickSelectEntity> data) {
        moneyData.clear();
        moneyData.addAll(data);
    }

    /**
     * 报名结束时间
     */
    public void setEndTimeData(List<PickSelectEntity> data) {
        endTimeDate.clear();
        endTimeDate.addAll(data);
    }

    /**
     * 招标状态
     */
    public void setStatusData(List<PickSelectEntity> data) {
        statusDate.clear();
        statusDate.addAll(data);
    }

    /**
     * 资格审查方式
     */
    public void setTenderTypeData(List<PickSelectEntity> data) {
        tenderTypeDate.clear();
        tenderTypeDate.addAll(data);
    }

    /**
     * 报名开始时间
     */
    private void setStartTimeData(String[] strings) {
        for (String s : strings) {
            PickSelectEntity pickSelectEntity = new PickSelectEntity();
            if (s.contains("&")) {
                String[] splitText = s.split("&");
                pickSelectEntity.setNo(splitText[1]);
                pickSelectEntity.setProjectscale(splitText[0]);
            } else {
                pickSelectEntity.setNo("");
                pickSelectEntity.setProjectscale(s);
            }
            startTimeData.add(pickSelectEntity);
        }
    }

    /**
     * 工程类型
     *
     * @param packersEntities
     */
    public void setProjectTypeList(List<PickSelectEntity> packersEntities) {
        projectTypeDate.clear();
        projectTypeDate.addAll(packersEntities);
    }

    /**
     * 发布时间
     *
     * @param packersEntities
     */
    public void setReleaseTimeList(List<PickSelectEntity> packersEntities) {
        releaseTimeDate.clear();
        releaseTimeDate.addAll(packersEntities);
    }

    /**
     * 需求leixing
     *
     * @param packersEntities
     */
    public void setDemandTypeList(List<PickSelectEntity> packersEntities) {
        demandTypeDate.clear();
        demandTypeDate.addAll(packersEntities);
    }

    public void setProvinceDatas(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        if (data != null && data.size() > 0) {
            scrData = data;
            mAddressPop.setData(scrData, true);
        } else {
            viewModel.getProvinceData();
        }
    }

    private void initFilterData() {
        page = 1;
        requestBean.page = page;
        isLoadMore = false;
        if ("0".equals(allNo)) {  //全部---类型 地区
            if ("0".equals(fromWhere)) {
                viewModel.findTenderingHomeEsPage(page, goodsType, areaCode, cityNo);
            } else if ("1".equals(fromWhere)) {
                viewModel.findNoticeHomeEsPage(page, goodsType, areaCode, cityNo);
            }
        } else if ("1".equals(allNo)) {   //0招标大厅 招标公告---类型 招标状态 预算金额  资格审查方式  地区      1招标公告 招标报名---类型 报名结束时间 预算金额 资格审查方式 地区
            if ("0".equals(fromWhere)) {
                viewModel.tenderBidderList(page, goodsType, areaCode, cityNo, money, statusNo, tenderTypeNo);
            } else if ("1".equals(fromWhere)) {
                viewModel.getFindPreBiddingList(page, goodsType, areaCode, cityNo, money, endTimeNo, tenderTypeNo);
            }
        } else if ("2".equals(allNo)) {   //直接竞价---类型 预算金额 地区
            viewModel.getBiddingList(page, goodsType, areaCode, cityNo, money,fromWhere);
        } else if ("3".equals(allNo)) {   //招标预告---类型 报名开始时间 预算金额 资格审查方式 地区
            viewModel.tenderNoticeList(page, goodsType, areaCode, cityNo, money, applyTimeNo, tenderTypeNo);
        } else if ("4".equals(allNo)) {
            viewModel.getMaterialHomeList(demandTypeNo, requestBean);
        }
    }

    private void updateViewShow() {
        if ("0".equals(allNo)) {  //全部---类型 地区
            binding.tvCategory.setVisibility(View.VISIBLE);
            binding.tvAddress.setVisibility(View.VISIBLE);
            binding.type.setVisibility(View.GONE);
            binding.tvStatus.setVisibility(View.GONE);
            binding.tvApplyTime.setVisibility(View.GONE);
            binding.tvEndTime.setVisibility(View.GONE);
            binding.tvMoney.setVisibility(View.GONE);
            binding.tvTenderType.setVisibility(View.GONE);
            binding.tvDemandType.setVisibility(View.GONE);//需求类型
            binding.tvProjectType.setVisibility(View.GONE);//工程类型
            binding.tvReleaseTime.setVisibility(View.GONE);//发布时间
        } else if ("1".equals(allNo)) {   //0招标大厅 招标公告---类型 预算金额  资格审查方式  地区  招标状态     1招标公告 招标报名---类型 预算金额 资格审查方式 地区 报名结束时间
            binding.tvCategory.setVisibility(View.VISIBLE);
            binding.type.setVisibility(View.GONE);
            binding.tvAddress.setVisibility(View.VISIBLE);
            binding.tvMoney.setVisibility(View.VISIBLE);
            binding.tvTenderType.setVisibility(View.VISIBLE);
            binding.tvDemandType.setVisibility(View.GONE);//需求类型
            binding.tvProjectType.setVisibility(View.GONE);//工程类型
            binding.tvReleaseTime.setVisibility(View.GONE);//发布时间

            if ("0".equals(fromWhere)) {
                binding.tvStatus.setVisibility(View.VISIBLE);
                binding.tvApplyTime.setVisibility(View.GONE);
                binding.tvEndTime.setVisibility(View.GONE);
            } else if ("1".equals(fromWhere)) {
                binding.tvStatus.setVisibility(View.GONE);
                binding.tvApplyTime.setVisibility(View.GONE);
                binding.tvEndTime.setVisibility(View.VISIBLE);
            }
        } else if ("2".equals(allNo)) {   //直接竞价---类型 预算金额 地区
            binding.tvCategory.setVisibility(View.VISIBLE);
            binding.type.setVisibility(View.GONE);
            binding.tvAddress.setVisibility(View.VISIBLE);
            binding.tvMoney.setVisibility(View.VISIBLE);
            binding.tvStatus.setVisibility(View.GONE);
            binding.tvApplyTime.setVisibility(View.GONE);
            binding.tvEndTime.setVisibility(View.GONE);
            binding.tvTenderType.setVisibility(View.GONE);
            binding.tvDemandType.setVisibility(View.GONE);//需求类型
            binding.tvProjectType.setVisibility(View.GONE);//工程类型
            binding.tvReleaseTime.setVisibility(View.GONE);//发布时间
        } else if ("3".equals(allNo)) {   //招标预告---类型 报名开始时间 预算金额 资格审查方式 地区
            binding.tvCategory.setVisibility(View.VISIBLE);
            binding.type.setVisibility(View.GONE);
            binding.tvAddress.setVisibility(View.VISIBLE);
            binding.tvApplyTime.setVisibility(View.VISIBLE);
            binding.tvMoney.setVisibility(View.VISIBLE);
            binding.tvTenderType.setVisibility(View.VISIBLE);
            binding.tvEndTime.setVisibility(View.GONE);
            binding.tvStatus.setVisibility(View.GONE);
            binding.tvDemandType.setVisibility(View.GONE);//需求类型
            binding.tvProjectType.setVisibility(View.GONE);//工程类型
            binding.tvReleaseTime.setVisibility(View.GONE);//发布时间
        } else if ("4".equals(allNo)) {//需求预告-展示的菜单
            binding.tvCategory.setVisibility(View.GONE);
            binding.type.setVisibility(View.VISIBLE);
            binding.tvStatus.setVisibility(View.GONE);
            binding.tvApplyTime.setVisibility(View.GONE);
            binding.tvEndTime.setVisibility(View.GONE);
            binding.tvMoney.setVisibility(View.GONE);
            binding.tvTenderType.setVisibility(View.GONE);
            binding.tvDemandType.setVisibility(View.VISIBLE);//需求类型
            binding.tvProjectType.setVisibility(View.GONE);//工程类型
            binding.tvReleaseTime.setVisibility(View.VISIBLE);//发布时间
            binding.tvAddress.setVisibility(View.VISIBLE);//地区
            demandTypeName = "材料采购";
            demandTypeNo = "0";
            demandTypePopWindow.setDefItem();
            updateChooseTextStatus(binding.tvDemandType, 1, demandTypeName);
            demandTypePopWindow.setData(demandTypeDate, false);
            initFilterData();
            viewModel.getMaterialType();
        }
    }

    @Override
    public void onClick(View v) {
        Fragment parentFragment = getParentFragment();
        if (parentFragment != null && parentFragment instanceof MainRecruitmentFragment) {
            ((MainRecruitmentFragment) parentFragment).setExpanded(false);
        }
        switch (v.getId()) {
            case R.id.tv_all:
                if (TextUtils.isEmpty(allName)) {
                    allName = "全部";
                    pickAllPopWindow.setDefItem();
                }
                updateChooseTextStatus1(binding.tvAll, -1, allName);
                new Handler().postDelayed(() -> pickAllPopWindow.showPopWindow1(binding.tvAll), 200);
                pickAllPopWindow.setData(allHallData, false);
                break;
            case R.id.tv_category:
                if (TextUtils.isEmpty(goodsTypeName)) {
                    goodsTypeName = "类型";
                    pickGoodsTypePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvCategory, -1, goodsTypeName);
                new Handler().postDelayed(() -> pickGoodsTypePopWindow.showPopwindow0(binding.tvCategory), 200);
                pickGoodsTypePopWindow.setData(goodsTypeData, false);
                break;
            case R.id.type:
                showCategoryPop();
                break;
            case R.id.tv_status:
                if (TextUtils.isEmpty(statusName)) {
                    statusName = "招标状态";
                    pickStatusPopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvStatus, -1, statusName);
                new Handler().postDelayed(() -> pickStatusPopWindow.showPopwindow0(binding.tvStatus), 200);
                pickStatusPopWindow.setData(statusDate, false);
                break;
            case R.id.tv_apply_time:
                if (TextUtils.isEmpty(applyTimeName)) {
                    applyTimeName = "报名开始时间";
                    pickApplyTimePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvApplyTime, -1, applyTimeName);
                new Handler().postDelayed(() -> pickApplyTimePopWindow.showPopwindow0(binding.tvApplyTime), 200);
                pickApplyTimePopWindow.setData(startTimeData, false);
                break;
            case R.id.tv_money:
                if (TextUtils.isEmpty(moneyName)) {
                    moneyName = "预算金额";
                    pickMoneyPopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvMoney, -1, moneyName);
                new Handler().postDelayed(() -> pickMoneyPopWindow.showPopwindow0(binding.tvMoney), 200);
                pickMoneyPopWindow.setData(moneyData, false);
                break;
            case R.id.tv_end_time:
                if (TextUtils.isEmpty(endTimeName)) {
                    endTimeName = "报名结束时间";
                    pickEndTimePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvEndTime, -1, endTimeName);
                new Handler().postDelayed(() -> pickEndTimePopWindow.showPopwindow0(binding.tvEndTime), 200);
                pickEndTimePopWindow.setData(endTimeDate, false);
                break;
            case R.id.tv_tender_type:
                if (TextUtils.isEmpty(tenderTypeName)) {
                    tenderTypeName = "资格审查方式";
                    pickTenderTypePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvTenderType, -1, tenderTypeName);
                new Handler().postDelayed(() -> pickTenderTypePopWindow.showPopwindow0(binding.tvTenderType), 200);
                pickTenderTypePopWindow.setData(tenderTypeDate, false);
                break;
            case R.id.tv_address:
                if (scrData == null) {
                    viewModel.getProvinceData();
                    return;
                }
                if (TextUtils.isEmpty(areaName)) {
                    areaName = "地区";
                }
                updateChooseTextStatus(binding.tvAddress, TextUtils.isEmpty(areaCode) && TextUtils.isEmpty(cityNo) ? -1 : -2, areaName);
                new Handler().postDelayed(() -> mAddressPop.showPopwindow0(binding.tvAddress), 200);
                break;
            case R.id.tv_demand_type://需求类型
                if (TextUtils.isEmpty(demandTypeName)) {
                    demandTypeName = "材料采购";
                    demandTypePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvDemandType, -1, demandTypeName);
                new Handler().postDelayed(() -> demandTypePopWindow.showPopwindow0(binding.tvDemandType), 200);
                demandTypePopWindow.setData(demandTypeDate, false);
                break;
            case R.id.tv_project_type://工程类型
                if (TextUtils.isEmpty(projectTypeName)) {
                    projectTypeName = "工程类型";
                    projectTypePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvProjectType, -1, projectTypeName);
                new Handler().postDelayed(() -> projectTypePopWindow.showPopwindow0(binding.tvProjectType), 200);
                projectTypePopWindow.setData(projectTypeDate, false);
                break;
            case R.id.tv_release_time://发布时间
                if (TextUtils.isEmpty(releaseTimeName)) {
                    releaseTimeName = "发布时间";
                    releaseTimePopWindow.setDefItem();
                }
                updateChooseTextStatus(binding.tvReleaseTime, -1, releaseTimeName);
                new Handler().postDelayed(() -> releaseTimePopWindow.showPopwindow0(binding.tvReleaseTime), 200);
                releaseTimePopWindow.setData(releaseTimeDate, false);
                break;
        }
    }

    public void getHallTenderData(List<TenderAllListNewEntity> list) {
        if (list != null) {
            isEnableLoadMore = list.size() >= 10;
        }
        binding.swipeRefresh.finishLoadMore(true);
        if (isLoadMore) {
            if (list.size() > 0) {
                pickingAdapter.addDatas(list);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() > 0) {
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.empty.setVisibility(View.GONE);
                pickingAdapter.setDatas(list);
                binding.recyclerView.scrollToPosition(0);
                binding.scrollview.scrollTo(0, 0);
            } else {
                pickingAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.empty.setVisibility(View.VISIBLE);
            }
        }
    }


    public void getHallAllData(List<TenderAllListNewEntity> list) {
        if (list != null) {
            isEnableLoadMore = list.size() >= 10;
        }
        binding.swipeRefresh.finishLoadMore(true);
        if (isLoadMore) {
            if (list.size() > 0) {
                pickHallAllNewAdapter.addDatas(list);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() > 0) {
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.empty.setVisibility(View.GONE);
                pickHallAllNewAdapter.setDatas(list);
                binding.recyclerView.scrollToPosition(0);
                binding.scrollview.scrollTo(0, 0);
            } else {
                pickHallAllNewAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.empty.setVisibility(View.VISIBLE);
            }
        }
    }

    public void getBiddingData(List<TenderAllListNewEntity> list) {
        if (list != null) {
            isEnableLoadMore = list.size() >= 10;
        }
        binding.swipeRefresh.finishLoadMore(true);
        if (isLoadMore) {
            if (list.size() > 0) {
                pickBidingAdapter.addDatas(list);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() > 0) {
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.empty.setVisibility(View.GONE);
                pickBidingAdapter.setDatas(list);
                binding.recyclerView.scrollToPosition(0);
                binding.scrollview.scrollTo(0, 0);
            } else {
                pickBidingAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.empty.setVisibility(View.VISIBLE);
            }
        }
    }

    public void getNoticeData(List<PreNoticeItemEntity> list) {
        if (list != null) {
            isEnableLoadMore = list.size() >= 10;
        }
        binding.swipeRefresh.finishLoadMore(true);
        if (isLoadMore) {
            if (list.size() > 0) {
                pickNoticeListAdapter.addDatas(list);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() > 0) {
                pickNoticeListAdapter.setDatas(list);
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.empty.setVisibility(View.GONE);
                binding.recyclerView.scrollToPosition(0);
                binding.scrollview.scrollTo(0, 0);
            } else {
                pickNoticeListAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.empty.setVisibility(View.VISIBLE);
            }
        }
    }

    public void getUrl(String url, String id) {
        if (TextUtils.isEmpty(url)) return;
        WebViewX5HostActivity.start(getActivity(), url, id);
    }

    /**
     * 更新选项颜色
     */
    private void updateChooseTextStatus(PickPopWindowView pickPopWindowView, int value, String name) {
        if (!TextUtils.isEmpty(name)) {
            if (name.length() > 4) {
                name = name.substring(0, 4) + "...";
            }
        }
        if (value == -1 || value == -2) {
            binding.popLine.setVisibility(View.VISIBLE);
            pickPopWindowView.setChooseData(R.drawable.member_pop_blue_bg2, R.mipmap.ic_up_arrow_n, R.color.color_333333, true, name);
        } else if (value == 0) {
            binding.popLine.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333, false, name);
        } else {
            binding.popLine.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_new_blue_bg_10, R.mipmap.icon_down_red, R.color.color_main, false, name);
        }
    }


    /**
     * 更新选项颜色
     */
    private void updateChooseTextStatus1(PickPopWindowView pickPopWindowView, int value, String name) {
        if (value == -1 || value == -2) {
            binding.popLineAll.setVisibility(View.VISIBLE);
            pickPopWindowView.setChooseData(R.drawable.member_pop_blue_bg2, R.mipmap.ic_up_arrow_n, R.color.color_333333, true, name);
        } else if (value == 0) {
            binding.popLineAll.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333, false, name);
        } else {
            binding.popLineAll.setVisibility(View.GONE);
            pickPopWindowView.setChooseData(R.drawable.search_new_blue_bg_10, R.mipmap.icon_down_red, R.color.color_main, false, name);
        }
    }

    public void setTypeNo(String mType) {
        if (!isAdded()) {
            return;
        }
        if (TextUtils.isEmpty(mType)) {
            DialogHelper.dismissProgressDialog();
            return;
        }
        fromWhere = mType;
        allNo = "0";
        allName = "全部";
        updateChooseTextStatus(binding.tvAll, 0, allName);
        pickAllPopWindow.setDefItem();
        initAdapter();
        initFilterData();
        updateViewShow();
        clearPopWindowData();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * 需求预告数据类型
     *
     * @param data
     * @param isLastPage
     */
    public void setDemandList(List<DemandForecastListEntity> data, boolean isLastPage) {
        if (data != null) {
            isEnableLoadMore = data.size() >= 10;
        }
        binding.swipeRefresh.finishLoadMore(true);
        if (isLoadMore) {
            if (data != null && data.size() > 0) {
                demandlistadapter.addDatas(data);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (data != null && data.size() > 0) {
                binding.empty.setVisibility(View.GONE);
                binding.recyclerView.setVisibility(View.VISIBLE);
                demandlistadapter.setDatas(data);
            } else {
                demandlistadapter.clearDatas();
                binding.empty.setVisibility(View.VISIBLE);
                binding.recyclerView.setVisibility(View.GONE);
            }
        }
    }

    //类型-商品类型
    public void setMaterialType(List<CommonPopEntity> data) {
        this.commonlist = data;
        popCategory.setShowThreeRecycler(true);
        popCategory.setData(data, 0);
        requestBean.setCategoryId("");
        binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
    }

    //类型-机械类型
    public void setMechanicalType(List<CommonPopEntity> data) {
        this.commonlist = data;
        popCategory.setShowThreeRecycler(false);
        popCategory.setData(data, 0);
        requestBean.setCategoryId("");
        binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
    }

    //类型-设备类型
    public void setEquipmentType(List<CommonPopEntity> data) {
        this.commonlist = data;
        popCategory.setShowThreeRecycler(false);
        popCategory.setData(data, 0);
        requestBean.setCategoryId("");
        binding.type.updateChooseTextStatus(0, binding.type.getKeyName());
    }

    //显示类型弹窗
    public void showCategoryPop() {
        binding.popLine.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(mNo1)) {
            binding.type.updateChooseTextStatus(-2, null);
        } else {
            binding.type.updateChooseTextStatus(-1, binding.type.getKeyName());
        }
        new Handler().postDelayed(() ->  popCategory.showPopwindow0(binding.popLine), 200);
    }
}